﻿using System; 
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic; 
using System.Data;
using Bangle.DBUtility;
namespace Bangle.DAL  
{
	 	//T_Phone
		public partial class T_PhoneDAL
	{
   		     
		public bool Exists(Guid PhoneId)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from T_Phone");
			strSql.Append(" where ");
			                                       strSql.Append(" PhoneId = @PhoneId  ");
                            			SqlParameter[] parameters = {
					new SqlParameter("@PhoneId", SqlDbType.UniqueIdentifier,16)			};
			parameters[0].Value = PhoneId;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}
		
				
		
		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(Bangle.Model.T_Phone model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_Phone(");			
            strSql.Append("PhoneId,PhoneName,PhoneCode,SupplierId,RMB,PartNo,Specification,USD,PCS,CreateUserId,CreateTime,UpdateUserId,UpdateTime,Valid,ScreenId,ChipId,SeriesId,SalePoint,SystemId,FrequencyId,NetWorkId,SimTypeId,ScreenPixelId,RAMId,ROMId,CameraFrontId,CameraBackId,BatteryTypeId,EarphoneId,ChargerId,Color,Accessories,Size");
			strSql.Append(") values (");
            strSql.Append("@PhoneId,@PhoneName,@PhoneCode,@SupplierId,@RMB,@PartNo,@Specification,@USD,@PCS,@CreateUserId,@CreateTime,@UpdateUserId,@UpdateTime,@Valid,@ScreenId,@ChipId,@SeriesId,@SalePoint,@SystemId,@FrequencyId,@NetWorkId,@SimTypeId,@ScreenPixelId,@RAMId,@ROMId,@CameraFrontId,@CameraBackId,@BatteryTypeId,@EarphoneId,@ChargerId,@Color,@Accessories,@Size");            
            strSql.Append(") ");            
            		
			SqlParameter[] parameters = {
			            new SqlParameter("@PhoneId", SqlDbType.UniqueIdentifier,16) ,            
                        new SqlParameter("@PhoneName", SqlDbType.VarChar,200) ,            
                        new SqlParameter("@PhoneCode", SqlDbType.VarChar,100) ,            
                        new SqlParameter("@SupplierId", SqlDbType.UniqueIdentifier,16) ,            
                        new SqlParameter("@RMB", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@PartNo", SqlDbType.VarChar,200) ,            
                        new SqlParameter("@Specification", SqlDbType.VarChar,-1) ,            
                        new SqlParameter("@USD", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@PCS", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@CreateUserId", SqlDbType.Int,4) ,            
                        new SqlParameter("@CreateTime", SqlDbType.VarChar,20) ,            
                        new SqlParameter("@UpdateUserId", SqlDbType.Int,4) ,            
                        new SqlParameter("@UpdateTime", SqlDbType.VarChar,20) ,            
                        new SqlParameter("@Valid", SqlDbType.Int,4) ,            
                        new SqlParameter("@ScreenId", SqlDbType.Int,4) ,            
                        new SqlParameter("@ChipId", SqlDbType.Int,4) ,            
                        new SqlParameter("@SeriesId", SqlDbType.Int,4) ,            
                        new SqlParameter("@SalePoint", SqlDbType.VarChar,8000) ,            
                        new SqlParameter("@SystemId", SqlDbType.Int,4) ,            
                        new SqlParameter("@FrequencyId", SqlDbType.Int,4) ,            
                        new SqlParameter("@NetWorkId", SqlDbType.Int,4) ,            
                        new SqlParameter("@SimTypeId", SqlDbType.Int,4) ,            
                        new SqlParameter("@ScreenPixelId", SqlDbType.Int,4) ,            
                        new SqlParameter("@RAMId", SqlDbType.Int,4) ,            
                        new SqlParameter("@ROMId", SqlDbType.Int,4) ,            
                        new SqlParameter("@CameraFrontId", SqlDbType.Int,4) ,            
                        new SqlParameter("@CameraBackId", SqlDbType.Int,4) ,            
                        new SqlParameter("@BatteryTypeId", SqlDbType.Int,4) ,            
                        new SqlParameter("@EarphoneId", SqlDbType.Int,4) ,            
                        new SqlParameter("@ChargerId", SqlDbType.Int,4) ,            
                        new SqlParameter("@Color", SqlDbType.NVarChar,1000) ,            
                        new SqlParameter("@Accessories", SqlDbType.NVarChar,1000) ,            
                        new SqlParameter("@Size", SqlDbType.NVarChar,1000)             
              
            };
			            
            parameters[0].Value = model.PhoneId;                        
            parameters[1].Value = model.PhoneName;                        
            parameters[2].Value = model.PhoneCode;                        
            parameters[3].Value = model.SupplierId;                        
            parameters[4].Value = model.RMB;                        
            parameters[5].Value = model.PartNo;                        
            parameters[6].Value = model.Specification;                        
            parameters[7].Value = model.USD;                        
            parameters[8].Value = model.PCS;                        
            parameters[9].Value = model.CreateUserId;                        
            parameters[10].Value = model.CreateTime;                        
            parameters[11].Value = model.UpdateUserId;                        
            parameters[12].Value = model.UpdateTime;                        
            parameters[13].Value = model.Valid;                        
            parameters[14].Value = model.ScreenId;                        
            parameters[15].Value = model.ChipId;                        
            parameters[16].Value = model.SeriesId;                        
            parameters[17].Value = model.SalePoint;                        
            parameters[18].Value = model.SystemId;                        
            parameters[19].Value = model.FrequencyId;                        
            parameters[20].Value = model.NetWorkId;                        
            parameters[21].Value = model.SimTypeId;                        
            parameters[22].Value = model.ScreenPixelId;                        
            parameters[23].Value = model.RAMId;                        
            parameters[24].Value = model.ROMId;                        
            parameters[25].Value = model.CameraFrontId;                        
            parameters[26].Value = model.CameraBackId;                        
            parameters[27].Value = model.BatteryTypeId;                        
            parameters[28].Value = model.EarphoneId;                        
            parameters[29].Value = model.ChargerId;                        
            parameters[30].Value = model.Color;                        
            parameters[31].Value = model.Accessories;                        
            parameters[32].Value = model.Size;                        
			            DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
            			
		}
		
		
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Bangle.Model.T_Phone model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_Phone set ");
			                        
            strSql.Append(" PhoneId = @PhoneId , ");                                    
            strSql.Append(" PhoneName = @PhoneName , ");                                    
            strSql.Append(" PhoneCode = @PhoneCode , ");                                    
            strSql.Append(" SupplierId = @SupplierId , ");                                    
            strSql.Append(" RMB = @RMB , ");                                    
            strSql.Append(" PartNo = @PartNo , ");                                    
            strSql.Append(" Specification = @Specification , ");                                    
            strSql.Append(" USD = @USD , ");                                    
            strSql.Append(" PCS = @PCS , ");                                    
            strSql.Append(" CreateUserId = @CreateUserId , ");                                    
            strSql.Append(" CreateTime = @CreateTime , ");                                    
            strSql.Append(" UpdateUserId = @UpdateUserId , ");                                    
            strSql.Append(" UpdateTime = @UpdateTime , ");                                    
            strSql.Append(" Valid = @Valid , ");                                    
            strSql.Append(" ScreenId = @ScreenId , ");                                    
            strSql.Append(" ChipId = @ChipId , ");                                    
            strSql.Append(" SeriesId = @SeriesId , ");                                    
            strSql.Append(" SalePoint = @SalePoint , ");                                    
            strSql.Append(" SystemId = @SystemId , ");                                    
            strSql.Append(" FrequencyId = @FrequencyId , ");                                    
            strSql.Append(" NetWorkId = @NetWorkId , ");                                    
            strSql.Append(" SimTypeId = @SimTypeId , ");                                    
            strSql.Append(" ScreenPixelId = @ScreenPixelId , ");                                    
            strSql.Append(" RAMId = @RAMId , ");                                    
            strSql.Append(" ROMId = @ROMId , ");                                    
            strSql.Append(" CameraFrontId = @CameraFrontId , ");                                    
            strSql.Append(" CameraBackId = @CameraBackId , ");                                    
            strSql.Append(" BatteryTypeId = @BatteryTypeId , ");                                    
            strSql.Append(" EarphoneId = @EarphoneId , ");                                    
            strSql.Append(" ChargerId = @ChargerId , ");                                    
            strSql.Append(" Color = @Color , ");                                    
            strSql.Append(" Accessories = @Accessories , ");                                    
            strSql.Append(" Size = @Size  ");            			
			strSql.Append(" where PhoneId=@PhoneId  ");
						
SqlParameter[] parameters = {
			            new SqlParameter("@PhoneId", SqlDbType.UniqueIdentifier,16) ,            
                        new SqlParameter("@PhoneName", SqlDbType.VarChar,200) ,            
                        new SqlParameter("@PhoneCode", SqlDbType.VarChar,100) ,            
                        new SqlParameter("@SupplierId", SqlDbType.UniqueIdentifier,16) ,            
                        new SqlParameter("@RMB", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@PartNo", SqlDbType.VarChar,200) ,            
                        new SqlParameter("@Specification", SqlDbType.VarChar,-1) ,            
                        new SqlParameter("@USD", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@PCS", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@CreateUserId", SqlDbType.Int,4) ,            
                        new SqlParameter("@CreateTime", SqlDbType.VarChar,20) ,            
                        new SqlParameter("@UpdateUserId", SqlDbType.Int,4) ,            
                        new SqlParameter("@UpdateTime", SqlDbType.VarChar,20) ,            
                        new SqlParameter("@Valid", SqlDbType.Int,4) ,            
                        new SqlParameter("@ScreenId", SqlDbType.Int,4) ,            
                        new SqlParameter("@ChipId", SqlDbType.Int,4) ,            
                        new SqlParameter("@SeriesId", SqlDbType.Int,4) ,            
                        new SqlParameter("@SalePoint", SqlDbType.VarChar,8000) ,            
                        new SqlParameter("@SystemId", SqlDbType.Int,4) ,            
                        new SqlParameter("@FrequencyId", SqlDbType.Int,4) ,            
                        new SqlParameter("@NetWorkId", SqlDbType.Int,4) ,            
                        new SqlParameter("@SimTypeId", SqlDbType.Int,4) ,            
                        new SqlParameter("@ScreenPixelId", SqlDbType.Int,4) ,            
                        new SqlParameter("@RAMId", SqlDbType.Int,4) ,            
                        new SqlParameter("@ROMId", SqlDbType.Int,4) ,            
                        new SqlParameter("@CameraFrontId", SqlDbType.Int,4) ,            
                        new SqlParameter("@CameraBackId", SqlDbType.Int,4) ,            
                        new SqlParameter("@BatteryTypeId", SqlDbType.Int,4) ,            
                        new SqlParameter("@EarphoneId", SqlDbType.Int,4) ,            
                        new SqlParameter("@ChargerId", SqlDbType.Int,4) ,            
                        new SqlParameter("@Color", SqlDbType.NVarChar,1000) ,            
                        new SqlParameter("@Accessories", SqlDbType.NVarChar,1000) ,            
                        new SqlParameter("@Size", SqlDbType.NVarChar,1000)             
              
            };
						            
            parameters[0].Value = model.PhoneId;                        
            parameters[1].Value = model.PhoneName;                        
            parameters[2].Value = model.PhoneCode;                        
            parameters[3].Value = model.SupplierId;                        
            parameters[4].Value = model.RMB;                        
            parameters[5].Value = model.PartNo;                        
            parameters[6].Value = model.Specification;                        
            parameters[7].Value = model.USD;                        
            parameters[8].Value = model.PCS;                        
            parameters[9].Value = model.CreateUserId;                        
            parameters[10].Value = model.CreateTime;                        
            parameters[11].Value = model.UpdateUserId;                        
            parameters[12].Value = model.UpdateTime;                        
            parameters[13].Value = model.Valid;                        
            parameters[14].Value = model.ScreenId;                        
            parameters[15].Value = model.ChipId;                        
            parameters[16].Value = model.SeriesId;                        
            parameters[17].Value = model.SalePoint;                        
            parameters[18].Value = model.SystemId;                        
            parameters[19].Value = model.FrequencyId;                        
            parameters[20].Value = model.NetWorkId;                        
            parameters[21].Value = model.SimTypeId;                        
            parameters[22].Value = model.ScreenPixelId;                        
            parameters[23].Value = model.RAMId;                        
            parameters[24].Value = model.ROMId;                        
            parameters[25].Value = model.CameraFrontId;                        
            parameters[26].Value = model.CameraBackId;                        
            parameters[27].Value = model.BatteryTypeId;                        
            parameters[28].Value = model.EarphoneId;                        
            parameters[29].Value = model.ChargerId;                        
            parameters[30].Value = model.Color;                        
            parameters[31].Value = model.Accessories;                        
            parameters[32].Value = model.Size;                        
            int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		
		
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(Guid PhoneId)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_Phone ");
			strSql.Append(" where PhoneId=@PhoneId ");
						SqlParameter[] parameters = {
					new SqlParameter("@PhoneId", SqlDbType.UniqueIdentifier,16)			};
			parameters[0].Value = PhoneId;


			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		
				
		
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Bangle.Model.T_Phone GetModel(Guid PhoneId)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select PhoneId, PhoneName, PhoneCode, SupplierId, RMB, PartNo, Specification, USD, PCS, CreateUserId, CreateTime, UpdateUserId, UpdateTime, Valid, ScreenId, ChipId, SeriesId, SalePoint, SystemId, FrequencyId, NetWorkId, SimTypeId, ScreenPixelId, RAMId, ROMId, CameraFrontId, CameraBackId, BatteryTypeId, EarphoneId, ChargerId, Color, Accessories, Size  ");			
			strSql.Append("  from T_Phone ");
			strSql.Append(" where PhoneId=@PhoneId ");
						SqlParameter[] parameters = {
					new SqlParameter("@PhoneId", SqlDbType.UniqueIdentifier,16)			};
			parameters[0].Value = PhoneId;

			
			Bangle.Model.T_Phone model=new Bangle.Model.T_Phone();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			
			if(ds.Tables[0].Rows.Count>0)
			{
																								if(ds.Tables[0].Rows[0]["PhoneId"].ToString()!="")
				{
					model.PhoneId= Guid.Parse(ds.Tables[0].Rows[0]["PhoneId"].ToString());
				}
																								model.PhoneName= ds.Tables[0].Rows[0]["PhoneName"].ToString();
																																model.PhoneCode= ds.Tables[0].Rows[0]["PhoneCode"].ToString();
																																								if(ds.Tables[0].Rows[0]["SupplierId"].ToString()!="")
				{
					model.SupplierId= Guid.Parse(ds.Tables[0].Rows[0]["SupplierId"].ToString());
				}
																				if(ds.Tables[0].Rows[0]["RMB"].ToString()!="")
				{
					model.RMB=decimal.Parse(ds.Tables[0].Rows[0]["RMB"].ToString());
				}
																																				model.PartNo= ds.Tables[0].Rows[0]["PartNo"].ToString();
																																model.Specification= ds.Tables[0].Rows[0]["Specification"].ToString();
																												if(ds.Tables[0].Rows[0]["USD"].ToString()!="")
				{
					model.USD=decimal.Parse(ds.Tables[0].Rows[0]["USD"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["PCS"].ToString()!="")
				{
					model.PCS=decimal.Parse(ds.Tables[0].Rows[0]["PCS"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["CreateUserId"].ToString()!="")
				{
					model.CreateUserId=int.Parse(ds.Tables[0].Rows[0]["CreateUserId"].ToString());
				}
																																				model.CreateTime= ds.Tables[0].Rows[0]["CreateTime"].ToString();
																												if(ds.Tables[0].Rows[0]["UpdateUserId"].ToString()!="")
				{
					model.UpdateUserId=int.Parse(ds.Tables[0].Rows[0]["UpdateUserId"].ToString());
				}
																																				model.UpdateTime= ds.Tables[0].Rows[0]["UpdateTime"].ToString();
																												if(ds.Tables[0].Rows[0]["Valid"].ToString()!="")
				{
					model.Valid=int.Parse(ds.Tables[0].Rows[0]["Valid"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["ScreenId"].ToString()!="")
				{
					model.ScreenId=int.Parse(ds.Tables[0].Rows[0]["ScreenId"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["ChipId"].ToString()!="")
				{
					model.ChipId=int.Parse(ds.Tables[0].Rows[0]["ChipId"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["SeriesId"].ToString()!="")
				{
					model.SeriesId=int.Parse(ds.Tables[0].Rows[0]["SeriesId"].ToString());
				}
																																				model.SalePoint= ds.Tables[0].Rows[0]["SalePoint"].ToString();
																												if(ds.Tables[0].Rows[0]["SystemId"].ToString()!="")
				{
					model.SystemId=int.Parse(ds.Tables[0].Rows[0]["SystemId"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["FrequencyId"].ToString()!="")
				{
					model.FrequencyId=int.Parse(ds.Tables[0].Rows[0]["FrequencyId"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["NetWorkId"].ToString()!="")
				{
					model.NetWorkId=int.Parse(ds.Tables[0].Rows[0]["NetWorkId"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["SimTypeId"].ToString()!="")
				{
					model.SimTypeId=int.Parse(ds.Tables[0].Rows[0]["SimTypeId"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["ScreenPixelId"].ToString()!="")
				{
					model.ScreenPixelId=int.Parse(ds.Tables[0].Rows[0]["ScreenPixelId"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["RAMId"].ToString()!="")
				{
					model.RAMId=int.Parse(ds.Tables[0].Rows[0]["RAMId"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["ROMId"].ToString()!="")
				{
					model.ROMId=int.Parse(ds.Tables[0].Rows[0]["ROMId"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["CameraFrontId"].ToString()!="")
				{
					model.CameraFrontId=int.Parse(ds.Tables[0].Rows[0]["CameraFrontId"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["CameraBackId"].ToString()!="")
				{
					model.CameraBackId=int.Parse(ds.Tables[0].Rows[0]["CameraBackId"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["BatteryTypeId"].ToString()!="")
				{
					model.BatteryTypeId=int.Parse(ds.Tables[0].Rows[0]["BatteryTypeId"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["EarphoneId"].ToString()!="")
				{
					model.EarphoneId=int.Parse(ds.Tables[0].Rows[0]["EarphoneId"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["ChargerId"].ToString()!="")
				{
					model.ChargerId=int.Parse(ds.Tables[0].Rows[0]["ChargerId"].ToString());
				}
																																				model.Color= ds.Tables[0].Rows[0]["Color"].ToString();
																																model.Accessories= ds.Tables[0].Rows[0]["Accessories"].ToString();
																																model.Size= ds.Tables[0].Rows[0]["Size"].ToString();
																										
				return model;
			}
			else
			{
				return null;
			}
		}
		
		
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select * ");
			strSql.Append(" FROM T_Phone ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}
		
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" * ");
			strSql.Append(" FROM T_Phone ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

   
	}
}

